﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing; 
using System.Text;
using System.Windows.Forms;
using ICSharpCode.TextEditor;
using System.Diagnostics;
using System.IO;
using ICSharpCode.TextEditor.Document;
using DevelopAssistant.Service;

namespace DevelopAssistant.Core.ToolBox
{
    public partial class FindAndReplace : ToolBoxBase //ToolBoxBase
    {
        private FindAndReplaceRequest Request = null;
        private IDocumentContent DocumentContent = null;
        private Rectangle workArea = new Rectangle();

        public FindAndReplace()
        {
            InitializeComponent();
        }

        public FindAndReplace(MainForm OwnerForm, IDocumentContent DocumentContent)
            : this()
        {
            this.Owner = OwnerForm;
            this.Request = new FindAndReplaceRequest();
            this.DocumentContent = DocumentContent;
            this.XTheme = AppSettings.WindowTheme;
            this.NToolBar.BorderColor = AppSettings.WindowTheme.FormBorderOutterColor;            
        }      

        private void btnLook_Click(object sender, EventArgs e)
        {
            Request.CommandText = "Look";
            if (!string.IsNullOrEmpty(txtLookFor.Text))
            {
                Request.LookFor = txtLookFor.Text.Trim();
                Request.MatchCase = chkMatchCase.Checked;
                DocumentContent.FindAndReplace(Request);
            }            
        }

        private void btnReplace_Click(object sender, EventArgs e)
        {
            Request.CommandText = "Replace";
            Request.LookFor = txtLookFor.Text.Trim();
            Request.ReplaceWith = txtReplaceWith.Text.Trim();
            Request.MatchCase = chkMatchCase.Checked;
            DocumentContent.FindAndReplace(Request);
        }

        private void LoadXTheme()
        {
            this.NToolBar.BorderColor = this.XTheme.FormBorderOutterColor;
        }

        private void FindAndReplace_Load(object sender, EventArgs e)
        {
            ((MainForm)Owner).SetWindowAtDockPanCenter(this);
        }

    }

}
